#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <iostream>
#include <opencv.hpp>


using namespace cv;
using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    /*Mat A(4,5,CV_32FC1,0.0);
    A.at<float>(2,2) = 19;
    Mat B(A);
    B.at<float>(3,3) = 4;
    //can i out put Mat
    cout << A << endl;
    */
    // read image
    Mat A;
    A = imread("image1.jpg");
    if(!A.data) {
        cout << "error in reading image1.jpg" << endl;
        return;
    }
    cout << "image size:" << A.size().width << " " << A.size().height << endl;

    Mat B=Mat::zeros(A.size(), A.type());
    for(int y=0;y<A.rows;y++){
        for(int x=0;x<A.cols;x++){
            for(int z=0;z<3;z++){
                B.at<Vec3b>(y,x)[z] = saturate_cast<uchar>( 0.3*A.at<Vec3b>(y,x)[z]+0.5 );
            }
        }
    }

    //show image
    namedWindow("window1");
    imshow("window1", A);
    namedWindow("window2");
    imshow("window2", B);

}
